<script setup lang="ts">
  import { ref, computed, watch, onMounted } from 'vue';
  import { useBooleanStore } from '@/store';
  import { palletDataSearch } from '@/api/inventory-management';
  import { PalletDataParam } from '@/api/inventory-management/types';
  import { Notification } from '@arco-design/web-vue';

  const booleanStore = useBooleanStore();
  const emit = defineEmits(['updateArray']);
  const pageSize = ref<number>(10);
  const pageNumber = ref<number>(1);
  const palletCode = ref<string>('');
  // 发送搜索数据
  const flowQueryData = computed<PalletDataParam>(() => ({
    searchParams: {
      palletCode: palletCode.value,
    },
    pageParameter: {
      rows: pageSize.value,
      page: pageNumber.value,
    },
  }));
  async function handleSearch() {
    const newData = await palletDataSearch(flowQueryData.value);
    console.log(newData.responseBody);
    if (newData.retCode === '200') {
      emit('updateArray', newData.responseBody);
    } else {
      Notification.error({
        title: '失败',
        content: newData.message ? newData.message : '查询失败',
        closable: true,
      });
    }
  }
  function reset() {
    palletCode.value = '';
    setTimeout(() => {
      handleSearch();
    }, 150);
  }
  // 监听分页
  watch([() => booleanStore.pageNum, () => booleanStore.pageSize], () => {
    if (booleanStore.num5 === 31) {
      pageNumber.value = booleanStore.pageNum;
      pageSize.value = booleanStore.pageSize;
      handleSearch();
    }
  });
  onMounted(() => {
    handleSearch();
  });
</script>

<template>
  <a-row :gutter="{ md: 8, lg: 24, xl: 32 }">
    <a-col :span="6" class="input-col">
      <a-input
        v-model="palletCode"
        placeholder="操作盘"
        size="large"
        allow-clear
        @press-enter="handleSearch"
      ></a-input
    ></a-col>
  </a-row>
  <div>
    <a-button type="primary" size="large" @click="handleSearch">查询</a-button>
    <a-button class="btn-reset" size="large" @click="reset">重置</a-button>
  </div>
</template>

<style scoped>
  .input-col {
    margin-bottom: 16px;
  }
  .btn-reset {
    margin-left: 10px;
  }
</style>
